package com.billing.web.controller.archives;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.billing.config.ServiceConfig;
import com.billing.model.entity.PersonalfilesDataModel;
import com.billing.model.entity.TUser;
import com.billing.model.entity.TUserBuffer;
import com.billing.model.entity.TUserEducation;
import com.billing.model.entity.TUserEducationBuffer;
import com.billing.model.entity.TUserEmergencycontact;
import com.billing.model.entity.TUserEmergencycontactBuffer;
import com.billing.model.entity.TUserPrivate;
import com.billing.model.entity.TUserPrivateBuffer;
import com.billing.model.entity.TUserScan;
import com.billing.model.entity.TUserScanBuffer;
import com.billing.model.entity.TUserWorkexperience;
import com.billing.model.entity.TUserWorkexperienceBuffer;
import com.billing.service.LeaveService;
import com.billing.service.MaindataService;
import com.billing.service.OvertimeService;
import com.billing.service.RecordService;
import com.billing.service.UserBeanService;
import com.billing.service.UserBufferService;
import com.billing.service.UserEducationBufferService;
import com.billing.service.UserEducationService;
import com.billing.service.UserEmergencycontactBufferService;
import com.billing.service.UserEmergencycontactService;
import com.billing.service.UserPrivateBufferService;
import com.billing.service.UserPrivateService;
import com.billing.service.UserScanBufferService;
import com.billing.service.UserScanService;
import com.billing.service.UserService;
import com.billing.service.UserWorkexperienceBufferService;
import com.billing.service.UserWorkexperienceService;
import com.billing.utils.BankCardPicApiUtil;
import com.billing.utils.IdIdentificationApiUtil;

/**
 * 档案信息
 * @author LYL
 *
 */
@RequestMapping(value="/archives")
@Controller
public class UserAppController {
	@Resource
	private RecordService recordService;
	@Resource
	private MaindataService maindataService;
	@Resource
	private LeaveService leaveService;
	@Resource
	private OvertimeService overtimeService;
	@Resource
	private UserBeanService userBeanService;
	@Resource
	private UserService userService;
	@Resource
	private UserBufferService userCopyService;
	@Resource
	private UserScanService userScanService;
	@Resource
	private UserScanBufferService userScanCopyService;
	@Resource
	private UserEducationService userEducationService;
	@Resource
	private UserEducationBufferService userEducationCopyService;
	@Resource
	private UserEmergencycontactService userEmergencycontactService;
	@Resource
	private UserEmergencycontactBufferService userEmergencycontactCopyService;
	@Resource
	private UserWorkexperienceService userWorkexperienceService;
	@Resource
	private UserWorkexperienceBufferService userWorkexperienceCopyService;
	@Resource
	private UserPrivateService userPrivateService;
	@Resource
	private UserPrivateBufferService userPrivateCopyService;
	SimpleDateFormat mdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
	SimpleDateFormat formatym = new SimpleDateFormat("yyyy-MM");
	
	/**
	 * APP按ID查找学历信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/getEducationByid", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String getEducationByid(HttpServletRequest request, Model model) {
//		String sign=null;
		JSONObject jsonObject = null;
		String msg=null;
		String userid=null;
		String eduid = null;
		String json = request.getParameter("json");
		jsonObject = JSONObject.fromObject(json);
        try {
            json = java.net.URLDecoder.decode(json,"UTF-8");
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }
		try{
//			sign =jsonObject.getString("sign");
			userid=jsonObject.getString("userid");
			eduid = jsonObject.getString("eduid");
		}catch(Exception e){
            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
		//判断用户信息
		TUser user=userService.selectTUserId(userid);
//		if (user == null) {
//			msg="{\"code\":\"2\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.GETEDUCATIONBYID, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		Map<String, Object> map=new HashMap<String, Object>();
		if(user!=null){
//			TUserEducation educationbean = userEducationService.selectUserEducationById(eduid);
			TUserEducationBuffer educationCopy = userEducationCopyService.selectUserEducationById(eduid);
			Map<String, Object> datemap=new HashMap<String, Object>();
			datemap.put("basic", educationCopy);
			map.put("code", 1);
			map.put("data", datemap);
		}else{
			map.put("code", 2);
			map.put("msg", "用户不存在");
		}
		JSONObject jsons = JSONObject.fromObject(map);
		msg=jsons.toString();
		
		return msg;
	}
	
	/**
	 * APP新增/更新学历保存
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/addEducation", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String addEducation(HttpServletRequest request, Model model) {
//		String sign = null;
		JSONObject jsonObject = null;
		String msg = null;
		String userid = null;
		String json = request.getParameter("json");
		try {
			json = java.net.URLDecoder.decode(json,"UTF-8");
	    } catch (UnsupportedEncodingException e1) {
	    	e1.printStackTrace();
	    }
		jsonObject = JSONObject.fromObject(json);
		String graduationtime = null;
		String universitie = null;
		String major = null;
		String educationNum = null;
		String academicdegreeNum = null;
		String educationPath = null;
		String academicdegreePath = null;
		String educationUploadtime = null;
		String academicdegreeUploadtime = null;
		String eduid = null;
		try{
//			sign =jsonObject.getString("sign");
			userid = jsonObject.getString("userid");
			graduationtime = jsonObject.getString("graduationtime");
			universitie = jsonObject.getString("universitie");
			major = jsonObject.getString("major");
			educationNum = jsonObject.getString("educationNum");
			academicdegreeNum = jsonObject.getString("academicdegreeNum");
			educationPath = jsonObject.getString("educationPath");
			academicdegreePath = jsonObject.getString("academicdegreePath");
			educationUploadtime = jsonObject.getString("educationUploadtime");
			academicdegreeUploadtime = jsonObject.getString("academicdegreeUploadtime");
			eduid = jsonObject.getString("eduid");
		}catch(Exception e){
            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
		//判断用户信息
//		TUser user=userService.selectTUserId(userid);
//		if (user == null) {
//			msg="{\"code\":\"2\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.ADDEDUCATION, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		Long graduationtimeLong = null;
		Long educationUploadtimeLong = null;
		Long academicdegreeUploadtimeLong = null;
		try {
			graduationtimeLong = formatym.parse(graduationtime).getTime();
			educationUploadtimeLong = format.parse(educationUploadtime).getTime();
			academicdegreeUploadtimeLong = format.parse(academicdegreeUploadtime).getTime();
		} catch (Exception e) {
		}
		TUserEducation userEducation = new TUserEducation();
		userEducation.setUserId(Integer.parseInt(userid));
		userEducation.setGraduationtime(graduationtimeLong);
		userEducation.setUniversitie(universitie);
		userEducation.setMajor(major);
		userEducation.setEducationNum(educationNum);
		userEducation.setAcademicdegreeNum(academicdegreeNum);
		if(educationPath != null && !educationPath.equals("")){
			userEducation.setEducationPath(educationPath);
		}
		if(academicdegreePath != null && !academicdegreePath.equals("")){
			userEducation.setAcademicdegreePath(academicdegreePath);
		}
		userEducation.setEducationUploadtime(educationUploadtimeLong);
		userEducation.setAcademicdegreeUploadtime(academicdegreeUploadtimeLong);
		try {
			if(eduid.equals("0")){
//				userEducationService.insertTUserEducation(userEducation);
				userEducationCopyService.insertTUserEducationByMain(userEducation);
			}else{
				userEducation.setId(Integer.parseInt(eduid));
//				userEducationService.updateUserEducation(userEducation);
				userEducationCopyService.updateUserEducationByMain(userEducation);
			}
			//资料审核状态为未通过
			userService.updateExamineStatus(userid, "2");
		} catch (Exception e) {
			msg="{\"code\":\"2\",\"msg\":\"保存失败\"}";
			return msg;
		}
		msg="{\"code\":\"1\",\"msg\":\"保存成功\"}";
		return msg;
	}
	/**
	 * APP增加/更新附件信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/updateScan", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String updateScan(HttpServletRequest request, Model model) {
//		String sign = null;
		JSONObject jsonObject = null;
		String msg = null;
		JSONArray scanarr = null;
		String userid = null;
		String scanid = null;
		String type = null;
		String path = null;
		Long uploadtime = null;
		String json = request.getParameter("json");
		try {
			json = java.net.URLDecoder.decode(json,"UTF-8");
	    } catch (UnsupportedEncodingException e1) {
	    	e1.printStackTrace();
	    }
		jsonObject = JSONObject.fromObject(json);
		try{
//			sign =jsonObject.getString("sign");
			scanarr = jsonObject.getJSONArray("scanarr");
			userid = jsonObject.getString("userid");
		}catch(Exception e){
            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
		//判断用户信息
//		TUser user=userService.selectTUserId(userid);
//		if (user == null) {
//			msg="{\"code\":\"2\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.UPDATESCAN, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		for (int i = 0; i < scanarr.size(); i++) {
			try {
				scanid = scanarr.getJSONObject(i).getString("scanid");
				type = scanarr.getJSONObject(i).getString("type");
				path = scanarr.getJSONObject(i).getString("path");
				uploadtime = format.parse(scanarr.getJSONObject(i).getString("uploadtime")).getTime();
			} catch (Exception e) {
				 msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
		         return msg;
			}
			TUserScan userScan = new TUserScan();
			try {
				if(scanid.equals("0")){
					//新增操作
					userScan.setPath(path);
					userScan.setType(Integer.parseInt(type));
					userScan.setUserId(Integer.parseInt(userid));
					userScan.setUploadtime(uploadtime);
//					userScanService.insertTUserScan(userScan);
					userScanCopyService.insertTUserScanByUserScan(userScan);
				}else{
					//更新操作
					userScan.setId(Integer.parseInt(scanid));
					userScan.setPath(path);
					userScan.setUploadtime(uploadtime);
//					userScanService.updateUserScan(userScan);
					userScanCopyService.updateUserScanByUserScan(userScan);
				}
				//资料审核状态为未通过
				userService.updateExamineStatus(userid, "2");
			} catch (Exception e) {
				msg="{\"code\":\"2\",\"msg\":\"保存失败\"}";
				return msg;
			}
		}
		msg="{\"code\":\"1\",\"msg\":\"保存成功\"}";
		return msg;
	}
	/**
	 * APP个人档案信息界面
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/getPersonalfilesData", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String getPersonalfilesData(HttpServletRequest request, Model model) {
//		String sign=null;
		JSONObject jsonObject = null;
		String msg=null;
		String userid=null;
		String json = request.getParameter("json");
		try {
			json = java.net.URLDecoder.decode(json,"UTF-8");
	    } catch (UnsupportedEncodingException e1) {
	    	e1.printStackTrace();
	    }
		jsonObject = JSONObject.fromObject(json);
		try{
//			sign =jsonObject.getString("sign");
			userid=jsonObject.getString("userid");
			
		}catch(Exception e){
            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
		//判断用户信息
//		TUser user=userService.selectTUserId(userid);
//		if (user == null) {
//			msg="{\"code\":\"2\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.GETPERSONALFILESDATA, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		Map<String, Object> map=new HashMap<String, Object>();
		PersonalfilesDataModel personalfiles = new PersonalfilesDataModel();
		TUserBuffer userCopy = userCopyService.selectTUserId(userid);
		if(userCopy!=null){
			List<TUserScanBuffer> scanlist = userCopy.getScanlist();
			for (TUserScanBuffer tUserScan : scanlist) {
				if(tUserScan.getType() == 4 && tUserScan.getPath() != null){
					if(tUserScan.getPath() != null){
						personalfiles.setIdPath(ServiceConfig.webServiceUrl+tUserScan.getPath().split("upload")[1]);
					}
					personalfiles.setId(tUserScan.getId());
					if(tUserScan.getUploadtime() != null){
						personalfiles.setUploadtime(format.format(new Date(tUserScan.getUploadtime())));
					}
				}
				if(tUserScan.getType() == 12 && tUserScan.getPath() != null){
					if(tUserScan.getPath() != null){
						personalfiles.setIdbackPath(ServiceConfig.webServiceUrl+tUserScan.getPath().split("upload")[1]);
					}
					personalfiles.setBackid(tUserScan.getId());
				}
			}
			for (TUserEducationBuffer education : userCopy.getEducationlist()) {
				if(education.getGraduationtime() != null){
					education.setGraduationtimeString(formatym.format(new Date(education.getGraduationtime())));
				}
			}
			personalfiles.setUserEducations(userCopy.getEducationlist());
			Map<String, Object> datemap=new HashMap<String, Object>();
			datemap.put("basiclist", personalfiles);
			map.put("code", 1);
			map.put("data", datemap);
		}else{
			map.put("code", 2);
			map.put("msg", "用户不存在");
		}
		JSONObject jsons = JSONObject.fromObject(map);
		msg=jsons.toString();
		
		return msg;
	}
	
	/**
	 * APP我的紧急联系人
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/getEmergencycontact", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String getEmergencycontact(HttpServletRequest request, Model model) {
//		String sign=null;
		JSONObject jsonObject = null;
		String msg=null;
		String userid=null;
		String json = request.getParameter("json");
		try {
			json = java.net.URLDecoder.decode(json,"UTF-8");
	    } catch (UnsupportedEncodingException e1) {
	    	e1.printStackTrace();
	    }
		jsonObject = JSONObject.fromObject(json);
		try{
//			sign =jsonObject.getString("sign");
			userid=jsonObject.getString("userid");
		}catch(Exception e){
            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
		//判断用户信息
//		TUser user=userService.selectTUserId(userid);
//		if (user == null) {
//			msg="{\"code\":\"2\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.GETEMERGENCYCONTACT, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		Map<String, Object> map=new HashMap<String, Object>();
		Map<String, Object> datemap = new HashMap<>(); 
		List<TUserEmergencycontactBuffer> emergencycontactlist = new ArrayList<>();
		TUserBuffer userCopy = userCopyService.selectTUserId(userid);
		if(userCopy!=null){
			emergencycontactlist = userCopy.getUserEmergencycontactlist();
			datemap.put("basiclist", emergencycontactlist);
			map.put("code", 1);
			map.put("data", datemap);
		}else{
			map.put("code", 2);
			map.put("msg", "用户不存在");
		}
		JSONObject jsons = JSONObject.fromObject(map);
		msg=jsons.toString();
		
		return msg;
	}
	/**
	 * APP按ID查找紧急联系人
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/getEmergencycontactByid", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String getEmergencycontactByid(HttpServletRequest request, Model model) {
//		String sign=null;
		JSONObject jsonObject = null;
		String msg=null;
		String userid=null;
		String emeid = null;
		String json = request.getParameter("json");
		try {
			json = java.net.URLDecoder.decode(json,"UTF-8");
	    } catch (UnsupportedEncodingException e1) {
	    	e1.printStackTrace();
	    }
		jsonObject = JSONObject.fromObject(json);
		try{
//			sign =jsonObject.getString("sign");
			userid=jsonObject.getString("userid");
			emeid = jsonObject.getString("emeid");
		}catch(Exception e){
            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
		//判断用户信息
		TUser user=userService.selectTUserId(userid);
//		if (user == null) {
//			msg="{\"code\":\"2\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.GETEMERGENCYCONTACTBYID, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		Map<String, Object> map=new HashMap<String, Object>();
		if(user!=null){
			TUserEmergencycontactBuffer emebean = userEmergencycontactCopyService.selectUserEmergencycontactByid(emeid);
			Map<String, Object> datemap=new HashMap<String, Object>();
			datemap.put("basic", emebean);
			map.put("code", 1);
			map.put("data", datemap);
		}else{
			map.put("code", 2);
			map.put("msg", "用户不存在");
		}
		JSONObject jsons = JSONObject.fromObject(map);
		msg=jsons.toString();
		
		return msg;
	}
	
	
	/**
	 * APP增加/更新我的紧急联系人
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/addEmergencycontact", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String addEmergencycontact(HttpServletRequest request, Model model) {
//		String sign = null;
		JSONObject jsonObject = null;
		String msg = null;
		String userid = null;
		String json = request.getParameter("json");
		try {
			json = java.net.URLDecoder.decode(json,"UTF-8");
	    } catch (UnsupportedEncodingException e1) {
	    	e1.printStackTrace();
	    }
		jsonObject = JSONObject.fromObject(json);
		String name = null;
		String relationship = null;
		String mobile = null;
		String age = null;
		String positions = null;
		String emeid = null;
		try{
//			sign =jsonObject.getString("sign");
			userid = jsonObject.getString("userid");
			name = jsonObject.getString("name");
			relationship = jsonObject.getString("relationship");
			mobile = jsonObject.getString("mobile");
			age = jsonObject.getString("age");
			positions = jsonObject.getString("positions");
			emeid = jsonObject.getString("emeid");
		}catch(Exception e){
            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
		//判断用户信息
//		TUser user=userService.selectTUserId(userid);
//		if (user == null) {
//			msg="{\"code\":\"2\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.ADDEMERGENCYCONTACT, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		TUserEmergencycontact emergencycontact = new TUserEmergencycontact();
		emergencycontact.setUserId(Integer.parseInt(userid));
		emergencycontact.setName(name);
		emergencycontact.setRelationship(relationship);
		emergencycontact.setMobile(mobile);
		emergencycontact.setAge(Integer.parseInt(age));
		emergencycontact.setPositions(positions);
		try {
			if(emeid.equals("0")){
				userEmergencycontactCopyService.insertTUserEmergencycontactByMain(emergencycontact);
			}else{
				emergencycontact.setId(Integer.parseInt(emeid));
				userEmergencycontactCopyService.updateUserEmergencycontactByMain(emergencycontact);
			}
			//资料审核状态为未通过
			userService.updateExamineStatus(userid, "2");
		} catch (Exception e) {
			msg="{\"code\":\"2\",\"msg\":\"保存失败\"}";
			return msg;
		}
		msg="{\"code\":\"1\",\"msg\":\"保存成功\"}";
		return msg;
	}
	/**
	 * APP按ID查找私密信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/getPrivateByid", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String getPrivateByid(HttpServletRequest request, Model model) {
//		String sign=null;
		JSONObject jsonObject = null;
		String msg=null;
		String userid=null;
		String privateid = null;
		String json = request.getParameter("json");
		try {
			json = java.net.URLDecoder.decode(json,"UTF-8");
	    } catch (UnsupportedEncodingException e1) {
	    	e1.printStackTrace();
	    }
		jsonObject = JSONObject.fromObject(json);
		try{
//			sign =jsonObject.getString("sign");
			userid=jsonObject.getString("userid");
			privateid = jsonObject.getString("privateid");
		}catch(Exception e){
            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
		//判断用户信息
		TUser user=userService.selectTUserId(userid);
//		if (user == null) {
//			msg="{\"code\":\"2\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.GETPRIVATEBYID, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		Map<String, Object> map=new HashMap<String, Object>();
		if(user!=null){
			TUserPrivateBuffer privatebean = userPrivateCopyService.selectUserPrivateById(privateid);
			Map<String, Object> datemap=new HashMap<String, Object>();
			datemap.put("basic", privatebean);
			map.put("code", 1);
			map.put("data", datemap);
		}else{
			map.put("code", 2);
			map.put("msg", "用户不存在");
		}
		JSONObject jsons = JSONObject.fromObject(map);
		msg=jsons.toString();
		
		return msg;
	}
	/**
	 * APP按userID查找私密信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/getPrivateByuid", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String getPrivateByuid(HttpServletRequest request, Model model) {
//		String sign=null;
		JSONObject jsonObject = null;
		String msg=null;
		String userid=null;
//		String privateid = null;
		String json = request.getParameter("json");
		try {
			json = java.net.URLDecoder.decode(json,"UTF-8");
	    } catch (UnsupportedEncodingException e1) {
	    	e1.printStackTrace();
	    }
		jsonObject = JSONObject.fromObject(json);
		try{
//			sign =jsonObject.getString("sign");
			userid=jsonObject.getString("userid");
		}catch(Exception e){
            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
		//判断用户信息
//		TUser user=userService.selectTUserId(userid);
//		if (user == null) {
//			msg="{\"code\":\"2\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.GETPRIVATEBYUID, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		Map<String, Object> map=new HashMap<String, Object>();
		TUserBuffer userCopy = userCopyService.selectTUserId(userid);
		if(userCopy!=null){
			TUserPrivateBuffer privatebean = userCopy.getUserPrivate();
			if(privatebean.getBankpath() != null){
				privatebean.setShowBankpath(ServiceConfig.webServiceUrl+privatebean.getBankpath().split("upload")[1]);
			}
			Map<String, Object> datemap=new HashMap<String, Object>();
			datemap.put("basic", privatebean);
			map.put("code", 1);
			map.put("data", datemap);
		}else{
			map.put("code", 2);
			map.put("msg", "用户不存在");
		}
		JSONObject jsons = JSONObject.fromObject(map);
		msg=jsons.toString();
		
		return msg;
	}
	/**
	 * APP更新私密信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/updatePrivateData", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String updatePrivateData(HttpServletRequest request, Model model) {
//		String sign=null;
		JSONObject jsonObject = null;
		String msg=null;
		String userid=null;
		String json = request.getParameter("json");
		try {
			json = java.net.URLDecoder.decode(json,"UTF-8");
	    } catch (UnsupportedEncodingException e1) {
	    	e1.printStackTrace();
	    }
		jsonObject = JSONObject.fromObject(json);
//		String privateid=null;
		String accumulationno=null;
		String securityno=null;
		String bankcardno=null;
		String bankname=null;
		String bankpath=null;
		String uploadtime = null;
		try{
//			sign =jsonObject.getString("sign");
			userid=jsonObject.getString("userid");
//			privateid=jsonObject.getString("privateid");
			accumulationno=jsonObject.getString("accumulationno");
			securityno=jsonObject.getString("securityno");
			bankcardno=jsonObject.getString("bankcardno");
			bankname=jsonObject.getString("bankname");
			bankpath=jsonObject.getString("bankpath");
			uploadtime = jsonObject.getString("uploadtime");
			
		}catch(Exception e){
            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
		//判断用户信息
//		TUser user=userService.selectTUserId(userid);
//		if (user == null) {
//			msg="{\"code\":\"2\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.UPDATEPRIVATEDATA, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		TUserPrivate userPrivate = new TUserPrivate();
		userPrivate.setAccumulationno(accumulationno);
		userPrivate.setBankcardno(bankcardno);
		userPrivate.setBankname(bankname);
		userPrivate.setSecurityno(securityno);
		userPrivate.setBankpath(bankpath);
		userPrivate.setUserId(Integer.parseInt(userid));
		Long uploadtimelong = null;
		if(uploadtime != null && !uploadtime.equals("")){
			try {
				uploadtimelong = format.parse(uploadtime).getTime();
			} catch (Exception e) {
			}
		}
		userPrivate.setUploadtime(uploadtimelong);
//		userPrivate.setId(Integer.parseInt(privateid));
		try {
			if(userPrivateCopyService.selectUserPrivateByUid(userid) == null){
				userPrivateCopyService.insertTUserPrivateByMain(userPrivate);
			}else {
				userPrivateCopyService.updateUserPrivateByUidByMain(userPrivate);
			}
			//资料审核状态为未通过
			userService.updateExamineStatus(userid, "2");
		} catch (Exception e) {
			msg="{\"code\":\"2\",\"msg\":\"更新数据失败\"}";
			return msg;
		}
			msg="{\"code\":\"1\",\"msg\":\"更新数据成功\"}";
			return msg;
	}
	/**
	 * APP更新紧急人信息
	 * @param request
	 * @param model
	 * @return
	 */
//	@RequestMapping(value = "/updateEmeData", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
//	@ResponseBody
//	public String updateEmeData(HttpServletRequest request, Model model) {
//		String sign=null;
//		JSONObject jsonObject = null;
//		String msg=null;
//		String userid=null;
//		String json = request.getParameter("json");
//		jsonObject = JSONObject.fromObject(json);
//		String emeid=null;
//		String name=null;
//		String relationship=null;
//		String mobile=null;
//		String age=null;
//		String positions=null;
//		try{
//			sign =jsonObject.getString("sign");
//			userid=jsonObject.getString("userid");
//			emeid=jsonObject.getString("emeid");
//			name=jsonObject.getString("name");
//			relationship=jsonObject.getString("relationship");
//			mobile=jsonObject.getString("mobile");
//			age=jsonObject.getString("age");
//			positions=jsonObject.getString("positions");
//			
//		}catch(Exception e){
//            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
//            return msg;
//		}
//		TUserEmergencycontact userEmergencycontact=userEmergencycontactService.selectUserEmergencycontactByUid(userid);
//		if(!"".equals(age)){
//			userEmergencycontact.setAge(Integer.parseInt(age));
//		}
//		userEmergencycontact.setMobile(mobile);
//		userEmergencycontact.setName(name);
//		userEmergencycontact.setPositions(positions);
//		userEmergencycontact.setRelationship(relationship);
//		int m=userEmergencycontactService.updateUserEmergencycontact(userEmergencycontact);
//		if(m>0){
//			msg="{\"code\":\"1\",\"msg\":\"更新数据成功\"}";
//		}else{
//			msg="{\"code\":\"2\",\"msg\":\"更新数据失败\"}";
//		}
//		return msg;
//	}
	/**
	 * APP我的工作经历
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/getWork", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String getWork(HttpServletRequest request, Model model) {
//		String sign=null;
		JSONObject jsonObject = null;
		String msg=null;
		String userid=null;
		String json = request.getParameter("json");
		try {
			json = java.net.URLDecoder.decode(json,"UTF-8");
	    } catch (UnsupportedEncodingException e1) {
	    	e1.printStackTrace();
	    }
		jsonObject = JSONObject.fromObject(json);
		try{
//			sign =jsonObject.getString("sign");
			userid=jsonObject.getString("userid");
			
		}catch(Exception e){
            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
		//判断用户信息
//		TUser user=userService.selectTUserId(userid);
//		if (user == null) {
//			msg="{\"code\":\"2\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.GETWORK, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		Map<String, Object> map=new HashMap<String, Object>();
		Map<String, Object> datemap = new HashMap<>(); 
		List<TUserWorkexperienceBuffer> worklist = new ArrayList<>();
		TUserBuffer userCopy = userCopyService.selectTUserId(userid);
		if(userCopy!=null){
			worklist = userCopy.getUserWorkexperiencelist();
			datemap.put("basiclist", worklist);
			map.put("code", 1);
			map.put("data", datemap);
		}else{
			map.put("code", 2);
			map.put("msg", "用户不存在");
		}
		JSONObject jsons = JSONObject.fromObject(map);
		msg=jsons.toString();
		
		return msg;
	}
	/**
	 * APP按ID查找工作经历信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/getWorkDataByid", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String getWorkDataByid(HttpServletRequest request, Model model) {
//		String sign=null;
		JSONObject jsonObject = null;
		String msg=null;
		String userid=null;
		String workid = null;
		String json = request.getParameter("json");
		try {
			json = java.net.URLDecoder.decode(json,"UTF-8");
	    } catch (UnsupportedEncodingException e1) {
	    	e1.printStackTrace();
	    }
		jsonObject = JSONObject.fromObject(json);
		try{
//			sign =jsonObject.getString("sign");
			userid=jsonObject.getString("userid");
			workid = jsonObject.getString("workid");
		}catch(Exception e){
            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
		//判断用户信息
		TUser user=userService.selectTUserId(userid);
//		if (user == null) {
//			msg="{\"code\":\"2\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.GETWORKDATABYID, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		Map<String, Object> map=new HashMap<String, Object>();
		if(user!=null){
			TUserWorkexperienceBuffer workbean = userWorkexperienceCopyService.selectUserWorkexperienceByid(workid);
			Map<String, Object> datemap=new HashMap<String, Object>();
			datemap.put("basic", workbean);
			map.put("code", 1);
			map.put("data", datemap);
		}else{
			map.put("code", 2);
			map.put("msg", "用户不存在");
		}
		JSONObject jsons = JSONObject.fromObject(map);
		msg=jsons.toString();
		
		return msg;
	}
	/**
	 * APP增加/更新工作经历信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/updateWorkData", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String updateWorkData(HttpServletRequest request, Model model) {
//		String sign=null;
		JSONObject jsonObject = null;
		String msg=null;
		String userid=null;
		String json = request.getParameter("json");
		try {
			json = java.net.URLDecoder.decode(json,"UTF-8");
	    } catch (UnsupportedEncodingException e1) {
	    	e1.printStackTrace();
	    }
		jsonObject = JSONObject.fromObject(json);
		String wordid=null;
		String start_time=null;
		String end_time=null;
		String unitname=null;
		String positions=null;
		String salaryStr=null;
		String witness=null;
		String mobile=null;
		try{
//			sign =jsonObject.getString("sign");
			userid=jsonObject.getString("userid");
			wordid=jsonObject.getString("wordid");
			start_time=jsonObject.getString("starttime");
			end_time=jsonObject.getString("endtime");
			unitname=jsonObject.getString("unitname");
			positions=jsonObject.getString("positions");
			salaryStr=jsonObject.getString("salary");
			witness=jsonObject.getString("witness");
			mobile=jsonObject.getString("mobile");
		}catch(Exception e){
            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
//		TUser user=userService.selectTUserId(userid);
//		if (user == null) {
//			msg="{\"code\":\"2\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.UPDATEWORKDATA, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		TUserWorkexperience userWorkexperience = new TUserWorkexperience();
		Double salary=0.00;
		if(!"".equals(salaryStr)){
			salary=Double.valueOf(salaryStr);
		}
		Long endtime;
	    Long starttime;
		try {
			endtime = formatym.parse(end_time).getTime();
			starttime = formatym.parse(start_time).getTime();
			userWorkexperience.setStarttime(starttime);
			userWorkexperience.setEndtime(endtime);
		} catch (ParseException e) {
		}
		userWorkexperience.setMobile(mobile);
		userWorkexperience.setPositions(positions);
		userWorkexperience.setSalary(salary);
		userWorkexperience.setUnitname(unitname);
		userWorkexperience.setWitness(witness);
		userWorkexperience.setUserId(Integer.parseInt(userid));
		try {
			if(wordid.equals("0")){
				userWorkexperienceCopyService.insertTUserWorkexperienceByMain(userWorkexperience);
			}else{
				userWorkexperience.setId(Integer.parseInt(wordid));
				userWorkexperienceCopyService.updateUserWorkexperienceByMain(userWorkexperience);
			}
			//资料审核状态为未通过
			userService.updateExamineStatus(userid, "2");
		} catch (Exception e) {
			msg="{\"code\":\"2\",\"msg\":\"更新数据失败\"}";
			return msg;
		}
		msg="{\"code\":\"1\",\"msg\":\"更新数据成功\"}";
		return msg;
	}
	/**
	 * APP更新学历信息
	 * @param request
	 * @param model
	 * @return
	 */
//	@RequestMapping(value = "/updateEducationData", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
//	@ResponseBody
//	public String updateEducationData(HttpServletRequest request, Model model) {
//		String sign=null;
//		JSONObject jsonObject = null;
//		String msg=null;
//		String userid=null;
//		String json = request.getParameter("json");
//		jsonObject = JSONObject.fromObject(json);
//		String eduid=null;
//		String graduationtime=null;
//		String universitie=null;
//		String major=null;
//		String educationNum=null;
//		String academicdegreeNum=null;
//		String educationPath=null;
//		String academicdegreePath=null;
//		
//		try{
//			sign =jsonObject.getString("sign");
//			userid=jsonObject.getString("userid");
//			eduid=jsonObject.getString("eduid");
//			graduationtime=jsonObject.getString("graduationtime");
//			universitie=jsonObject.getString("universitie");
//			major=jsonObject.getString("major");
//			educationNum=jsonObject.getString("educationNum");
//			academicdegreeNum=jsonObject.getString("academicdegreeNum");
//			//educationPath=jsonObject.getString("educationPath");
//			//academicdegreePath=jsonObject.getString("academicdegreePath");
//		}catch(Exception e){
//            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
//            return msg;
//		}
//		TUserEducation userEducation=userEducationService.selectUserEducationByUid(userid);
//		userEducation.setAcademicdegreeNum(academicdegreeNum);
//	    userEducation.setEducationNum(educationNum);
//	    Long gtime;
//		try {
//			gtime = format.parse(graduationtime).getTime();
//			userEducation.setGraduationtime(gtime);
//		} catch (ParseException e) {
//		}
//		userEducation.setMajor(major);
//		userEducation.setUniversitie(universitie);
//		int fal=userEducationService.updateUserEducation(userEducation);
//		//路径图片 未增加?
//		if(fal>0){
//			msg="{\"code\":\"1\",\"msg\":\"更新数据成功\"}";
//		}else{
//			msg="{\"code\":\"2\",\"msg\":\"更新数据失败\"}";
//		}
//		return msg;
//	}
	/**
	 * APP更新附件信息
	 * @param request
	 * @param model
	 * @return
	 */
//	@RequestMapping(value = "/updateScanData", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
//	@ResponseBody
//	public String updateScanData(HttpServletRequest request, Model model) {
//		String sign=null;
//		JSONObject jsonObject = null;
//		String msg=null;
//		String userid=null;
//		String json = request.getParameter("json");
//		jsonObject = JSONObject.fromObject(json);
//		String scanid=null;
//		String type=null;
//		String path=null;
//		try{
//			sign =jsonObject.getString("sign");
//			userid=jsonObject.getString("userid");
//			scanid=jsonObject.getString("scanid");
//			type=jsonObject.getString("type");
//			//path=jsonObject.getString("path");
//		}catch(Exception e){
//            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
//            return msg;
//		}
//		TUserScan userScan=userScanService.selectUserScanByUid(userid);
//		userScan.setType(Integer.valueOf(type));
//		int dd=userScanService.updateUserScan(userScan);
//		if(dd>0){
//			msg="{\"code\":\"1\",\"msg\":\"更新数据成功\"}";
//		}else{
//			msg="{\"code\":\"2\",\"msg\":\"更新数据失败\"}";
//		}
//		return msg;
//	}
	/**
	 * APP更新基本信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/updateBasicData", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String updateBasicData(HttpServletRequest request, Model model) {
//		String sign=null;//code+user.getId()+user.getToken()+user.getLogintime()
		JSONObject jsonObject = null;
		String msg=null;
		String userid=null;
		String json = request.getParameter("json");
		try {
			json = URLDecoder.decode(json,"UTF-8");
		} catch (UnsupportedEncodingException e2) {
			e2.printStackTrace();
		}
		jsonObject = JSONObject.fromObject(json);
		System.out.println(jsonObject.getString("sendaddress"));
		String name=null;//姓名
		String jobnumber=null;//工号
		String sex=null;//性别
		String datebirth=null;//出生日期
		String origin=null;//籍贯
		String nation=null;//民族
		String politicalstatus=null;//政治面貌
		String language=null;//语言
		String speciality=null;//特长
		String highesteducation=null;//最高学历
		String professional=null;//专业
		String idcard=null;//身份证号
		String maritalstatus=null;//婚姻状况
		String height=null;//身高
		String weight=null;//体重
		String vision=null;//视力
		String mobile=null;//手机
		String qq=null;//qq
		String mail=null;//邮件地址
		String weixinid=null;//微信号
		String birthplace=null;//户口所在地
		String address=null;//现居住地址
		String referee=null;//推荐人
		String ifsend=null;//是否接受外派
		String sendaddress=null;//外派地区
		try{
//			sign =jsonObject.getString("sign");
			userid=jsonObject.getString("userid");
			name=jsonObject.getString("name");
			jobnumber=jsonObject.getString("jobnumber");
			sex=jsonObject.getString("sex");
			datebirth=jsonObject.getString("datebirth");
			origin=jsonObject.getString("origin");
			nation=jsonObject.getString("nation");
			politicalstatus=jsonObject.getString("politicalstatus");
			language=jsonObject.getString("language");
			speciality=jsonObject.getString("speciality");
			highesteducation=jsonObject.getString("highesteducation");
			professional=jsonObject.getString("professional");
			idcard=jsonObject.getString("idcard");
			maritalstatus=jsonObject.getString("maritalstatus");
			height=jsonObject.getString("height");
			weight=jsonObject.getString("weight");
			vision=jsonObject.getString("vision");
			mobile=jsonObject.getString("mobile");
			qq=jsonObject.getString("qq");
			mail=jsonObject.getString("mail");
			weixinid=jsonObject.getString("weixinid");
			birthplace=jsonObject.getString("birthplace");
			address=jsonObject.getString("address");
			referee=jsonObject.getString("referee");
			ifsend=jsonObject.getString("ifsend");
			sendaddress=jsonObject.getString("sendaddress");
			String organizationid = jsonObject.getString("organizationid");
			if(mobile != null || !mobile.equals("")){
				//判断手机号码是否可以注册
				if(userService.userMobileIsExist(mobile,organizationid,userid)){
					msg="{\"code\":\"2\",\"msg\":\"手机号码已注册或上家公司未离职\"}";
					return msg;
				}
			}
			if(idcard != null || !idcard.equals("")){
				//判断身份证是否可以注册
				if(userService.userIdcardIsExist(idcard, organizationid,userid)){
					msg="{\"code\":\"2\",\"msg\":\"身份证号码已注册或上家公司未离职\"}";
					return msg;
				}
			}
		}catch(Exception e){
            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
		//判断用户信息
		TUser user=userService.selectTUserId(userid);
//		if (user == null) {
//			msg="{\"code\":\"2\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.UPDATEBASICDATA, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		int maritalstatus_=0;
        if(maritalstatus!=""&&maritalstatus!=null){
            maritalstatus_=Integer.parseInt(maritalstatus);
        }
        Long date_birth = null;
        if(!"".equals(datebirth)&&datebirth!=null){
            try {
                 date_birth=format.parse(datebirth).getTime();
            } catch (ParseException e1) {
                // TODO 自动生成的 catch 块
                e1.printStackTrace();
            }
        }
        Long modifytime=new Date().getTime();
		//查询数据by userid
//		TUser user=userService.selectTUserId(userid);
		user.setName(name);
        user.setJobnumber(jobnumber);
        user.setNation(nation);
        user.setLoginname(mobile);
		user.setSex(Integer.parseInt(sex));
		user.setDatebirth(date_birth);
		user.setOrigin(origin);
		user.setPoliticalstatus(politicalstatus);
		user.setLanguage(language);
		user.setSpeciality(speciality);
		user.setHighesteducation(highesteducation);
		user.setProfessional(professional);
		user.setIdcard(idcard);
		user.setMaritalstatus(maritalstatus_);
		user.setHeight(height);
		user.setWeight(weight);
		user.setVision(vision);
		user.setMobile(mobile);
		user.setQq(qq);
		user.setMail(mail);
		user.setWeixinid(weixinid);
		user.setBirthplace(birthplace);
		user.setAddress(address);
		user.setReferee(referee);
        user.setIfsend(Integer.parseInt(ifsend));
        user.setModifytime(modifytime);

		user.setSendaddress(sendaddress);
		int f=userCopyService.updateTUserByUser(user);
		System.out.println(userid+"受影响");
		//资料审核状态为未通过
		userService.updateExamineStatus(userid, "2");
		if(f>0){
			msg="{\"code\":\"1\",\"msg\":\"更新数据成功\"}";
		}else{
			msg="{\"code\":\"2\",\"msg\":\"更新数据失败\"}";
		}
		return msg;
		
	}
	/**
	 * APP保存人员信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/SaveArchivesData", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String SaveArchivesData(HttpServletRequest request, Model model) {
//		String sign=null;
//		JSONObject jsonObject = null;
//		String msg=null;
//		String userid=null;
//		String json = request.getParameter("json");
//		jsonObject = JSONObject.fromObject(json);
//		JSONObject dataObject;
//		
//		try{
//			sign =jsonObject.getString("sign");
//			userid=jsonObject.getString("userid");
//			
//		}catch(Exception e){
//            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
//            return msg;
//		}
		
		return null;
		
	}
	/**
	 * APP获取人员信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/getArchivesData", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String getUserDetail(HttpServletRequest request, Model model) {
//		String sign=null;
		JSONObject jsonObject = null;
		String msg=null;
		String userid=null;
		String json = request.getParameter("json");
		try {
			json = java.net.URLDecoder.decode(json,"UTF-8");
	    } catch (UnsupportedEncodingException e1) {
	    	e1.printStackTrace();
	    }
		jsonObject = JSONObject.fromObject(json);
		try{
//			sign =jsonObject.getString("sign");
			userid=jsonObject.getString("userid");
			
		}catch(Exception e){
            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
		//判断用户信息
		TUser user=userService.selectTUserId(userid);
//		if (user == null) {
//			msg="{\"code\":\"2\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.GETARCHIVESDATA, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		Map<String, Object> map=new HashMap<String, Object>();
		//user.getUserScan().setPath(webUrl+user.getUserScan().getPath());
		TUserBuffer userCopy = userCopyService.selectTUserId(userid);
		if(userCopy!=null){
//			List<TUserScanCopy> scanlist = userCopy.getScanlist();
//			for (TUserScanCopy tUserScan : scanlist) {
//				tUserScan.setPath(ServiceConfig.webServiceUrl+tUserScan.getPath());
//			}
			Map<String, Object> datemap=new HashMap<String, Object>();
			datemap.put("basiclist", userCopy);
			map.put("code", 1);
			map.put("data", datemap);
//			map.put("webUrl", webUrl);
		}else{
//			map.put("code", 2);
//			map.put("msg", "用户不存在");
			Map<String, Object> datemap=new HashMap<String, Object>();
			datemap.put("basiclist", user);
			map.put("code", 1);
			map.put("data", datemap);
		}
		JSONObject jsons = JSONObject.fromObject(map);
		msg=jsons.toString();
		
		return msg;
	}
	/**
	 * 文件上传
	 * @param request
	 * @param description
	 * @param file
	 * @return
	 */
	@RequestMapping(value = "upload",method = RequestMethod.POST,produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String upload(HttpServletRequest request,Model model,@RequestParam("file") MultipartFile file){
//		String sign = null;
		String msg = null;
		String userid = null;
		String filetype = null;
		String organizationid = null;
		String json = request.getParameter("json");
		try {
			json = java.net.URLDecoder.decode(json,"UTF-8");
	    } catch (UnsupportedEncodingException e1) {
	    	e1.printStackTrace();
	    }
		JSONObject jsonObject = JSONObject.fromObject(json);
		try{
//			sign =jsonObject.getString("sign");
			userid=jsonObject.getString("userid");
			filetype = jsonObject.getString("filetype");
			organizationid = jsonObject.getString("organizationid");
		}catch(Exception e){
            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
		//判断用户信息
		TUser user=userService.selectTUserId(userid);
//		if (user == null) {
//			msg="{\"code\":\"2\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.UPLOAD, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		//如果文件不为空，写入上传路径
        if(!file.isEmpty()) {
        	String subpath = null;
        	if(filetype.equals("1")){
        		subpath = "employee";
        	}else if(filetype.equals("2")){
        		subpath = "resume";
        	}else if(filetype.equals("3")){
        		subpath = "examination";
        	}else if(filetype.equals("4")){
        		subpath = "id";
        	}else if(filetype.equals("5")){
        		subpath = "education";
        	}else if(filetype.equals("6")){
        		subpath = "contract";
        	}else if(filetype.equals("7")){
        		subpath = "upLeavingCertificate";
        	}else if(filetype.equals("8")){
        		subpath = "leavingCertificateApproval";
        	}else if(filetype.equals("9")){
        		subpath = "leavingCertificate";
        	}else if(filetype.equals("10")){
        		subpath = "interviewRecords";
        	}else if(filetype.equals("11")){
        		subpath = "bankCard";
        	}else if(filetype.equals("12")){
        		subpath = "idBack";
        	}else if(filetype.equals("13")){
        		subpath = "education";
        	}else if(filetype.equals("14")){
        		subpath = "academicdegree";
        	}else if(filetype.equals("15")){
        		subpath = "bankpath";
        	}else if(filetype.equals("16")){
        		subpath = "leave";
        	}else if(filetype.equals("17")){
        		subpath = "currency";
        	}else{
        		msg="{\"code\":\"2\",\"msg\":\"上传类型错误\"}";
    			return msg;
        	}
        	
        	//上传文件路径
            String path = ServiceConfig.fileUploadPath+"/"+subpath+"/"+userid;
            //保存数据库路径
            String sqlPath = "upload"+"/"+subpath+"/"+userid;
            //上传文件名
            String filename = file.getOriginalFilename();
            try {
				filename = URLDecoder.decode(filename,"utf-8");
			} catch (UnsupportedEncodingException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
            File filepath = new File(path,filename);
            //判断路径是否存在，如果不存在就创建一个
            if (!filepath.getParentFile().exists()) { 
                filepath.getParentFile().mkdirs();
            }
            String nameCode = UUID.randomUUID().toString().replace("-", "");
            String pathFilename = path + "/" + nameCode + filename;
            String sqlPathName = sqlPath + "/" + nameCode + filename;
            //将上传文件保存到一个目标文件当中
            try {
				file.transferTo(new File(pathFilename));
			} catch (IllegalStateException e) {
				msg="{\"code\":\"2\",\"msg\":\"上传文件失败\"}";
				return msg;
			} catch (IOException e) {
				msg="{\"code\":\"2\",\"msg\":\"上传文件失败\"}";
				return msg;
			}
            Map<String, Object> map = new HashMap<>();
            Map<String, Object> map2 = new HashMap<>();
            map2.put("pathFilename", sqlPathName);
            map2.put("showPathFilename",ServiceConfig.webServiceUrl+subpath+"/"+userid+"/"+nameCode + filename);
            map2.put("uploadtime", format.format(new Date()));
//            if(filetype.equals("4")){//身份证图片识别数据
//            	map.put("iddata", IdIdentificationApiUtil.getIdImageData(pathFilename));
//            }else if (filetype.equals("15")) {//银行卡图片识别数据
//				map.put("bankdata", BankCardPicApiUtil.getBankData(pathFilename));
//			}
            if(filetype.equals("4")){//身份证图片识别数据
            	Map<String, Object> map3 = IdIdentificationApiUtil.getIdImageData(pathFilename);
            	if((int)map3.get("idcode") == 0){
            		String num = (String)map3.get("num");
            		if(num != null || !num.trim().equals("")){
            			//判断身份证是否可以注册
            			if(userService.userIdcardIsExist((String)map3.get("num"), organizationid,userid)){
            				msg="{\"code\":\"2\",\"msg\":\"身份证号码已注册或上家公司未离职\"}";
            				return msg;
            			}
            		}
	        		  SimpleDateFormat idmdf = new SimpleDateFormat("yyyyMMdd"); 
	        		  TUser user2 = new TUser();
	        		  String address = (String)map3.get("address");
	        		  user2.setBirthplace(address);//地址
	        		  try {
	        			  user2.setDatebirth(idmdf.parse((String)map3.get("birth")).getTime());//出生日期
	        		  } catch (Exception e) {
	        		  }
	        		  user2.setName((String)map3.get("name"));//姓名
	        		  user2.setNation((String)map3.get("nationality"));//民族
	        		  user2.setIdcard((String)map3.get("num"));//身份证号码
	        		  if(map3.get("sex").equals("男")){
	        			  user2.setSex(1);
	        		  }else{
	        			  user2.setSex(2);
	        		  }
	        		  //更新用户表
	        		  user2.setId(user.getId());
	        		  userCopyService.updateTUserByUser(user2);
            	}
            }else if (filetype.equals("15")) {//银行卡图片识别数据
            	Map<String, Object> map3 = BankCardPicApiUtil.getBankData(pathFilename);
				if((int)map3.get("code") == 0){
					TUserPrivate private1 = new TUserPrivate();
					String cardnumber = (String)map3.get("cardnumber");
					private1.setBankcardno(cardnumber);
					private1.setUserId(user.getId());
					TUserPrivate private2 = userPrivateService.selectUserPrivateByUid(userid);
					if(private2 != null){
						userPrivateCopyService.updateUserPrivateByUidByMain(private1);
					}else {
						userPrivateCopyService.insertTUserPrivateByMain(private1);
					}
				}
            }
            map.put("code", "1");
            map.put("msg", "上传文件成功");
            map.put("data", map2);
            msg = JSONObject.fromObject(map).toString();
//            msg = "{\"code\":\"1\",\"msg\":\"上传文件成功\",data:{\"pathFilename\":\""+sqlPathName+"\",\"showPathFilename\":\""+FileUrl+sqlPathName+"\"}}";
        } else {
        	msg="{\"code\":\"2\",\"msg\":\"上传文件失败\"}";
        }
        return msg;
	}
//	/**
//	 * 文件上传(多个)
//	 * @param request
//	 * @param description
//	 * @param file
//	 * @return
//	 */
//	@RequestMapping(value = "uploads",method = RequestMethod.POST,produces = "text/json;charset=UTF-8")
//	@ResponseBody
//	public String upload(HttpServletRequest request,Model model,@RequestParam("files") MultipartFile[] files){
//		String sign = null;
//		JSONObject jsonObject = null;
//		//接收所有文件扫描表id 为0则为新增 否则为修改
//		JSONArray ids = null;
//		String msg = null;
//		String userid = null;
//		String type = null;
//		String json = request.getParameter("json");
//		jsonObject = JSONObject.fromObject(json);
//		try{
////			sign = jsonObject.getString("sign");
//			ids = jsonObject.getJSONArray("ids");
//			userid = jsonObject.getString("userid");
//			type = jsonObject.getString("type");
//		}catch(Exception e){
//            msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
//            return msg;
//		}
//		for (int i = 0; i < files.length; i++) {
//			//如果文件不为空，写入上传路径
//	        if(!files[i].isEmpty()) {
//	            //上传文件路径
//	            String path = request.getServletContext().getRealPath("upload");
//	            //上传文件名
//	            String filename = files[i].getOriginalFilename();
//	            File filepath = new File(path,filename);
//	            //判断路径是否存在，如果不存在就创建一个
//	            if (!filepath.getParentFile().exists()) { 
//	                filepath.getParentFile().mkdirs();
//	            }
//	            String pathFilename = path + File.separator + filename;
//	            //将上传文件保存到一个目标文件当中
//	            try {
//					files[i].transferTo(new File(pathFilename));
//				} catch (IllegalStateException e) {
//					msg="{\"code\":\"2\",\"msg\":\"上传文件失败\"}";
//				} catch (IOException e) {
//					msg="{\"code\":\"2\",\"msg\":\"上传文件失败\"}";
//				}
//	            TUserScan scan = new TUserScan();
//	            scan.setPath(pathFilename);
//	            int id = Integer.parseInt(ids.getJSONObject(i).getString("id"));
//	            if(id == 0){
//	            	scan.setType(Integer.parseInt(type));
//	            	scan.setUserId(Integer.parseInt(userid));
//	            	userScanService.insertTUserScan(scan);
//	            }else{
//	            	scan.setId(id);
//	            	userScanService.updateUserScan(scan);
//	            }
//	            msg="{\"code\":\"1\",\"msg\":\"上传文件成功\"}";
//			}else {
//	        	msg="{\"code\":\"2\",\"msg\":\"上传文件失败\"}";
//	        }
//		}
//        return msg;
//	}
}
